﻿using Benlai.Model.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;

namespace BenlaiStudy.Controllers
{
    public class HomeController : BaseController
    {
        //
        // GET: /_LayoutNavPartial/
        public ActionResult _LayoutNavPartial()
        {
            return View();
        }

        //
        // GET: /Home/
        public ActionResult Index()
        {
            ViewBag.MenuNo = 1001;
            return View();
        }

        //
        // GET: /Home/ApiDoc
        public ActionResult ApiDoc()
        {
            ViewBag.MenuNo = 10020004;
            return View();
        }

        //
        // GET: /Home/TreeData
        public ActionResult TreeData()
        {
            ViewBag.MenuNo = 10020003;
            return View();
        }


        [HttpGet]
        public JsonResult GetApiDoc(string no)
        {
            try
            {
                var model = new Benlai.Bll.Common.TreeManager().Get(no);
                return Json(model, JsonRequestBehavior.AllowGet);
            }
            catch
            {
                return Json(null, JsonRequestBehavior.AllowGet);
            }
        }

        [HttpGet]
        public JsonResult GetApiDocList(int type, int level)
        {
            try
            {
                var list = new Benlai.Bll.Common.TreeManager().GetList(type, level);
                return Json(list, JsonRequestBehavior.AllowGet);
            }
            catch
            {
                return Json(null, JsonRequestBehavior.AllowGet);
            }
        }

        [HttpGet]
        public JsonResult GetTreeList()
        {
            try
            {
                var list = new Benlai.Bll.Common.TreeManager().GetList();
                return Json(list, JsonRequestBehavior.AllowGet);
            }
            catch
            {
                return Json(null, JsonRequestBehavior.AllowGet);
            }
        }


        [HttpPost]
        public JsonResult SaveTree(TreeModel model)
        {
            try
            {
                new Benlai.Bll.Common.TreeManager().Save(model);
                return Json(100);
            }
            catch
            {
                return Json(-100);
            }
        }


        [HttpGet]
        public JsonResult GetNavigationList()
        {
            try
            {
                var list = new Benlai.Bll.Common.NavigationManager().GetList();
                return Json(list, JsonRequestBehavior.AllowGet);
            }
            catch
            {
                return Json(null, JsonRequestBehavior.AllowGet);
            }
        }
    }


}
